﻿using Inovout.Kuajing.Models;
using Inovout.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Inovout.Kuajing.Store.Web.Controllers
{
    public class WarehouseController :   KJBaseController<Warehouse>
    {  
        public  ActionResult Createhouse()
        {
            IRepositoryService<ShippingTemplate> shippingTemplateService = ComponentRegistry.Resolve<IRepositoryService<ShippingTemplate>>();
            IList<ShippingTemplate> listTemplate = shippingTemplateService.FindAll().ToList();
            
            
            //IList<Warehouse> Warehouse = (IList<Warehouse>)locationService.FindByParent(null);
            var data = listTemplate.Where(c => c.Consigner.Id == Consigner.Id).Select(c => new
            {
                ShippingTemplate_Id = c.Id.ToString(),
                ShippingTemplateName = c.Name
            });
            ViewData["ShippingTemplate"] = new SelectList(data.AsEnumerable(), "ShippingTemplate_Id", "ShippingTemplateName");
            return View();
        }

        [HttpPost]
        public ActionResult Create(Warehouse warehouse)
        {
            warehouse.Consigner = Consigner;
            IRepositoryService<Warehouse> shippingTemplateService = ComponentRegistry.Resolve<IRepositoryService<Warehouse>>();
            shippingTemplateService.Save(warehouse);
            return RedirectToAction("Createhouse");
        }
	}
}